package com.hy.example.shared.distribute.counter;

/**
 * 分布式计数器， 模仿 @see java.util.concurrent.atomic.AtomicLong 定义，提供JDK AtomicLong 一致的使用体验
 */
public interface DistCounter {
    long get();

    void set(long initValue);

    long getAndSet(long setValue);

    boolean compareAndSet(long expectedValue, long newValue);

    default long increase() {
        return increase(1L);
    }

    long increase(long delta);

    default long decrease() {
        return decrease(1L);
    }

    default long decrease(long delta) {
        return increase(-delta);
    }
}
